package com.swust.exam.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.swust.exam.pojo.Classes;
import com.swust.exam.pojo.Students;
import com.swust.exam.service.ClassesService;
import com.swust.exam.service.StudentsService;

@Controller
public class StudentsController {
	@Autowired
	private StudentsService studentsservice;
	@Autowired
	private  ClassesService classesservice;
	
	
	@RequestMapping(value="/students/get")
	public Students studentsGet(int id)
	{
		return studentsservice.get(id);
	}
	
	
	@RequestMapping(value="/students/delete")
	public String studentsDelete(int id,Model model) {
		studentsservice.delete(id);
		List<Students> studentslist=studentsservice.GetDetailStudentsInfo();
		model.addAttribute("studentslist",studentslist);
		List<Classes> CourseNamelist=classesservice.GetCourseName();
		model.addAttribute("CourseNamelist",CourseNamelist);
		List<Classes> classlist=classesservice.GetDetailClassInfo();
		model.addAttribute("classlist",classlist);
		return "students";
	}
	
	@RequestMapping(value="/students/insert")
	public String studentsInsert(Students info,Model model) {
		studentsservice.insert(info);	
		List<Students> studentslist=studentsservice.GetDetailStudentsInfo();
		List<Classes> classlist=classesservice.GetDetailClassInfo();
		List<Classes> CourseNamelist=classesservice.GetCourseName();
		model.addAttribute("CourseNamelist",CourseNamelist);
		model.addAttribute("classlist",classlist);
		model.addAttribute("studentslist",studentslist);
		return "students";
	}
	
	@RequestMapping(value="/students/update")
	public String studentsUpdate(Students Info,Model model) {
		studentsservice.update(Info);
		List<Students> studentslist=studentsservice.GetDetailStudentsInfo();
		List<Classes> classlist=classesservice.GetDetailClassInfo();
		List<Classes> CourseNamelist=classesservice.GetCourseName();
		model.addAttribute("CourseNamelist",CourseNamelist);
		model.addAttribute("classlist",classlist);
		model.addAttribute("studentslist",studentslist);
		return "students";
	}
}
